package com.jielin.handling.controller.getinformation;

import com.alibaba.fastjson.JSONObject;
import com.jielin.handling.Annotation.MyPower;
import com.jielin.handling.bean.AppResult;
import com.jielin.handling.entity.getinformation.GetInfromation;
import com.jielin.handling.service.getinformation.GetInformationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by wangjienice on 2019-04-13.
 */
@CrossOrigin
@RestController
@RequestMapping("/getInformation/")
@Slf4j
@MyPower(name = "嫌疑人信息采集模块", url = "/getInformation")
public class GetInformationController {
    @Autowired
    GetInformationService  getInformationService;
    /**
     * 新增信息采集登记
     */
    @MyPower(name = "新增信息采集登记", url = "/addInformation")
    @RequestMapping("addInformation")
    public AppResult addInformation(@RequestBody GetInfromation infromation) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        log.info("infromation:{}", JSONObject.toJSONString(infromation));
        getInformationService.deleteInformationService(infromation.getSuspectId());
        int value = getInformationService.addInformation(infromation);
        if (value > 0) {
            date.put("value", 1);
            appResult.setCode(200);
            appResult.setMsg("新增信息采集登记成功!");
            appResult.setData(date);
        } else {
            date.put("Value", 0);
            appResult.setCode(-1);
            appResult.setMsg("新增信息采集登记失败!");
            appResult.setData(date);
        }
        return appResult;
    }

    /**
     * 信息采集登记根据嫌疑人id查询嫌疑人
     * @param
     * @return
     */
    @MyPower(name = "信息采集登记根据嫌疑人id查询嫌疑人", url = "/selectInformation")
    @RequestMapping("selectInformation")
    public AppResult selectInformation(@RequestParam String suspectId) {
        log.info("suspectId:{}",JSONObject.toJSONString(suspectId));
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
       GetInfromation getInfromation = getInformationService.selectInformation(suspectId);
            date.put("value", getInfromation);
            appResult.setCode(200);
            appResult.setMsg("查询嫌疑人成功!");
            appResult.setData(date);
        return appResult;
    }

    /**
     *
     * 信息采集更新
     */
    @MyPower(name = "信息采集更新", url = "/updateInformation")
    @RequestMapping("updateInformation")
    public AppResult updateInformation(@RequestBody GetInfromation infromation) {
        log.info("infromation:{}",JSONObject.toJSONString(infromation));
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        int i = getInformationService.updateInformation(infromation);
        if (i>0) {
            date.put("value", 1);
            appResult.setCode(200);
            appResult.setMsg("更新信息采集成功!");
            appResult.setData(date);
        } else {
            date.put("Value", 0);
            appResult.setCode(-1);
            appResult.setMsg("查询信息采集(为空)!");
            appResult.setData(date);
        }
        return appResult;
    }
}
